<?
$link = OpenDB();
$templates = GetSQL($query);
$plantilla = "'";
if ($templates)
{
    foreach ($templates as $template)
    {
        if (isset($template["codigo"]))
        {
            $plantilla .= $template["codigo"] . "','";
        }
    }
}
$plantilla = rtrim($plantilla, ",'");
CloseDB($link);
?>
<fieldset id="inputPlantilla">
    <script type="text/javascript">
        $(function(){
            var plantillas = new Array(<?= $plantilla ?>');
            $("#plantilla").autocomplete({source: plantillas});
        });
    </script>
    <legend>Plantilla</legend>
    <input type="text" id="plantilla" name="plantilla" value="<?= (isset($codigo)) ? $codigo : "" ?>" />
    <div id="loadSaveButtons">
        <button id="templateButton" type="button">Cargar</button>
    </div>
</fieldset>